/**
 * This file is part of the Agora distribution. 
 * Detailed copyright and licensing information can be found
 * in the gpl-3.0.txt file which should be included in the distribution.
 * 
 * @version		$Id: 3.0.14 Olympus 2010-09-28 rammstein4o $
 * @copyright  2007 - 2010 jVitals
 * @license   GPLv3 Open Source
 * @link       http://jvitals.com
 * @since      File available since initial release
 */
 
function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
	request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
		return request_type;
}
var http = createObject();
function autosuggest() {
	var q = document.getElementById('searchb').value;
	var nocache = Math.random();
	http.open('get', SITE_ROOT + 'index.php?option=com_agora&task=pms&page=select&action=search&q='+q+'&nocache = '+nocache);
	http.onreadystatechange = autosuggestReply;
	http.send(null);
}
function autosuggestReply() {
	if(http.readyState == 4){
		var response = http.responseText;
		e = document.getElementById('results');
		if(response!=""){
			e.innerHTML=response;
			e.style.display="block";
		} else {
			e.style.display="none";
		}
	}
}
function addToPM(UID)
{
	var fx=new Fx.Style(document.getElementById('ag_queueCon'), "background-color", {duration:500});
	var nocache = Math.random();
        document.getElementById('ag_queueCon').innerHTML = '';
		document.getElementById('ag_queueLst').empty().addClass("ajax-loading").setHTML("<img src='"+assetsBase+"/ajax-loader.gif' border='0'> "+ _LOADING_ );
        var url = SITE_ROOT + "index.php?option=com_agora&task=pms&page=select&action=addrecipient&format=raw&id="+UID+"&nocache="+nocache;
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response) {
                var resp=Json.evaluate(response);
				if (resp.res){
					$('user'+UID).innerHTML = '';
					$('user'+UID).className='none';
				}
                document.getElementById('ag_queueLst').removeClass("ajax-loading").setHTML(resp.html);
                document.getElementById('ag_queueCon').setHTML(resp.msg);
				document.getElementById('ag_queueBot').setHTML(resp.links);
				document.getElementById('ag_queueTop').setHTML(resp.title);
				fx.set("#fff").start("#f60").chain(function() {
                    this.start.delay(500,this,"#fff");
			});
		}
	}).request();
}
function addSearchToPM(UID)
{
	var fx=new Fx.Style(document.getElementById('ag_queueCon'), "background-color", {duration:500});
	var nocache = Math.random();
        document.getElementById('ag_queueCon').innerHTML = '';
		document.getElementById('ag_queueLst').empty().addClass("ajax-loading").setHTML("<img src='"+assetsBase+"/ajax-loader.gif' border='0'> "+ _LOADING_ );
        var url = SITE_ROOT + "index.php?option=com_agora&task=pms&page=select&action=addrecipient&format=raw&id="+UID+"&nocache="+nocache;
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response) {
                var resp=Json.evaluate(response);
			if (resp.res){
				var sb = document.getElementById('searchb');
				if (sb) {
					sb.value = '';
				}
				document.getElementById('results').style.display="none";
			}
			document.getElementById('ag_queueLst').removeClass("ajax-loading").setHTML(resp.html);
			document.getElementById('ag_queueCon').setHTML(resp.msg);
			document.getElementById('ag_queueBot').setHTML(resp.links);
			document.getElementById('ag_queueTop').setHTML(resp.title);
			fx.set("#fff").start("#f60").chain(function() {
				this.start.delay(500,this,"#fff");
			});
		}
	}).request();
}
function remFromPM(UID)
{
	var fx=new Fx.Style(document.getElementById('ag_queueCon'), "background-color", {duration:500});
	var nocache = Math.random();
        document.getElementById('ag_queueCon').innerHTML = '';
		document.getElementById('ag_queueLst').empty().addClass("ajax-loading").setHTML("<img src='"+assetsBase+"/ajax-loader.gif' border='0'> "+ _LOADING_ );
        var url = SITE_ROOT + "index.php?option=com_agora&task=pms&page=select&action=remrecipient&format=raw&id="+UID+"&nocache="+nocache;
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response) {
                var resp=Json.evaluate(response);
				if (resp.res){
					document.getElementById('user'+UID).removeClass("innertxt").innerHTML = '';
				}
                document.getElementById('ag_queueLst').removeClass("ajax-loading").setHTML(resp.html);
                document.getElementById('ag_queueCon').setHTML(resp.msg);
				document.getElementById('ag_queueBot').setHTML(resp.links);
				document.getElementById('ag_queueTop').setHTML(resp.title);
				fx.set("#fff").start("#f60").chain(function() {
                    this.start.delay(500,this,"#fff");
			});
		}
	}).request();
}
function resetPM()
{
	var fx=new Fx.Style(document.getElementById('ag_queueCon'), "background-color", {duration:500});
	var nocache = Math.random();
        document.getElementById('ag_queueCon').innerHTML = '';
		document.getElementById('ag_queueLst').empty().addClass("ajax-loading").setHTML("<img src='"+assetsBase+"/ajax-loader.gif' border='0'> "+ _LOADING_ );
        var url = SITE_ROOT + "index.php?option=com_agora&task=pms&page=select&action=reset&format=raw&nocache="+nocache;
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response) {
                var resp=Json.evaluate(response);
                document.getElementById('ag_queueLst').removeClass("ajax-loading").setHTML(resp.html);
                document.getElementById('ag_queueCon').setHTML(resp.msg);
				document.getElementById('ag_queueBot').setHTML(resp.links);
				document.getElementById('ag_queueTop').setHTML(resp.title);
				fx.set("#fff").start("#f60").chain(function() {
                    this.start.delay(500,this,"#fff");
			});
		}
	}).request();
}
function resetPM2()
{
	var nocache = Math.random();
    var url = SITE_ROOT + "index.php?option=com_agora&task=pms&page=select&action=reset&format=raw&nocache="+nocache;
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response) {
				window.location.href=window.location.href;
		}
	}).request();
}

function updatePM(){
    var fx=new Fx.Style($("ag_queueCon"), "background-color", {duration:2000});
	var nocache = Math.random();
		$('ag_queueCon').innerHTML = '';
        $("ag_queueLst").empty().addClass("ajax-loading").setHTML("<img src='"+assetsBase+"/ajax-loader.gif' border='0'> "+ _LOADING_ );
        var url = SITE_ROOT + "index.php?option=com_agora&task=pms&page=select&action=update&format=raw&nocache="+nocache;
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response) {
                var resp=Json.evaluate(response);
                $("ag_queueLst").removeClass("ajax-loading").setHTML(resp.html);
                $("ag_queueCon").setHTML(resp.msg);
				$("ag_queueBot").setHTML(resp.links);
				$('ag_queueTop').setHTML(resp.title);
                fx.set("#fff").start("#f60").chain(function() {
                    this.start.delay(2000,this,"#FFF");
                });
            }
        }).request();
}

function sendPM() {
	var url = SITE_ROOT + "index.php?option=com_agora&task=pms&action=compose";
	window.location.href = SITE_ROOT + "index.php?option=com_agora&task=pms&page=compose&Itemid="+_Itemid_;
}